#ifndef __EVENTFD_HPP__
#define __EVENTFD_HPP__

#include <functional>

namespace xww
{
    using EventfdCallback = std::function<void()>;

    class Eventfd
    {
        public:
            Eventfd(EventfdCallback && cb);
            ~Eventfd();

            void start();
            void wakeup();
            void stop();

        private:
            int createEventfd();
            void handleReadEvent();

        private:
            int _eventfd;
            EventfdCallback _cb;
            bool _isStarted;
    };

} // end of namespace xww

#endif